<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input v-model="query.serialnumber" placeholder="任务编号" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-input v-model="query.missileNumber" placeholder="弹号" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-date-picker
          v-model="query.experimentDate"
          :default-time="['00:00:00','23:59:59']"
          type="daterange"
          range-separator=":"
          size="small"
          class="date-item"
          value-format="yyyy-MM-dd HH:mm:ss"
          start-placeholder="试验开始"
          end-placeholder="试验结束"
        />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="编号" prop="serialnumber">
            <el-input v-model="form.serialnumber" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="试验时间" prop="experimentDate">
            <el-date-picker v-model="form.experimentDate" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="弹号" prop="missileNumber">
            <el-input v-model="form.missileNumber" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="弹号名称" prop="missileName">
            <el-input v-model="form.missileName" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column v-if="columns.visible('serialnumber')" prop="serialnumber" label="编号" />
        <el-table-column v-if="columns.visible('experimentDate')" prop="experimentDate" label="试验时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.experimentDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('missileNumber')" prop="missileNumber" label="弹号" />
        <el-table-column v-if="columns.visible('missileName')" prop="missileName" label="弹号名称" />
        <el-table-column v-if="columns.visible('createUser')" prop="createUser" label="创建人" />
        <el-table-column v-if="columns.visible('createDate')" prop="createDate" label="创建时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('updateUser')" prop="updateUser" label="最后修改人" />
        <el-table-column v-if="columns.visible('updateDate')" prop="updateDate" label="最后修改时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.updateDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-permission="['admin','daTask:edit','daTask:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudDaTask from '@/api/daTask'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

// crud交由presenter持有
const defaultCrud = CRUD({ title: '任务管理', url: 'api/daTask', sort: 'id,desc', crudMethod: { ...crudDaTask }})
const defaultForm = { id: null, serialnumber: null, experimentDate: null, missileNumber: null, missileName: null, isDelete: null, createUser: null, createDate: null, updateUser: null, updateDate: null }
export default {
  name: 'DaTask',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  data() {
    return {
      permission: {
        add: ['admin', 'daTask:add'],
        edit: ['admin', 'daTask:edit'],
        del: ['admin', 'daTask:del']
      },
      rules: {
        serialnumber: [
          { required: true, message: '编号不能为空', trigger: 'blur' }
        ],
        experimentDate: [
          { required: true, message: '试验时间不能为空', trigger: 'blur' }
        ],
        missileNumber: [
          { required: true, message: '弹号不能为空', trigger: 'blur' }
        ],
        missileName: [
          { required: true, message: '弹号名称不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      const query = this.query
      if (query.type && query.value) {
        this.crud.params[query.type] = query.value
      }
      return true
    }
  }
}
</script>

<style scoped>

</style>
